home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / p_man / cat3 / perl5 / Net::servent.z / Net::servent
Encoding:
Text File  |  2002-10-03  |  3.6 KB  |  133 lines

  1.  
  2.  
  3.  
  4. NNNNeeeetttt::::::::sssseeeerrrrvvvveeeennnntttt((((3333))))                                                NNNNeeeetttt::::::::sssseeeerrrrvvvveeeennnntttt((((3333))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      Net::servent - by-name interface to Perl's built-in getserv*() functions
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.       use Net::servent;
  13.       $s = getservbyname(shift || 'ftp') || die "no service";
  14.       printf "port for %s is %s, aliases are %s\n",
  15.          $s->name, $s->port, "@{$s->aliases}";
  16.  
  17.       use Net::servent qw(:FIELDS);
  18.       getservbyname(shift || 'ftp') || die "no service";
  19.       print "port for $s_name is $s_port, aliases are @s_aliases\n";
  20.  
  21.  
  22. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  23.      This module's default exports override the core _g_e_t_s_e_r_v_e_n_t(),
  24.      _g_e_t_s_e_r_v_b_y_n_a_m_e(), and _g_e_t_n_e_t_b_y_p_o_r_t() functions, replacing them with
  25.      versions that return "Net::servent" objects.  They take default second
  26.      arguments of "tcp".  This object has methods that return the similarly
  27.      named structure field name from the C's servent structure from _n_e_t_d_b._h;
  28.      namely name, aliases, port, and proto.  The aliases method returns an
  29.      array reference, the rest scalars.
  30.  
  31.      You may also import all the structure fields directly into your namespace
  32.      as regular variables using the :FIELDS import tag.  (Note that this still
  33.      overrides your core functions.)  Access these fields as variables named
  34.      with a preceding n_.  Thus, $serv_obj->name() corresponds to $s_name if
  35.      you import the fields.  Array references are available as regular array
  36.      variables, so for example @{ $serv_obj->aliases() } would be simply
  37.      @s_aliases.
  38.  
  39.      The _g_e_t_s_e_r_v() function is a simple front-end that forwards a numeric
  40.      argument to _g_e_t_s_e_r_v_b_y_p_o_r_t(), and the rest to _g_e_t_s_e_r_v_b_y_n_a_m_e().
  41.  
  42.      To access this functionality without the core overrides, pass the use an
  43.      empty import list, and then access function functions with their full
  44.      qualified names.  On the other hand, the built-ins are still available
  45.      via the CORE:: pseudo-package.
  46.  
  47. EEEEXXXXAAAAMMMMPPPPLLLLEEEESSSS
  48.       use Net::servent qw(:FIELDS);
  49.  
  50.       while (@ARGV) {
  51.           my ($service, $proto) = ((split m!/!, shift), 'tcp');
  52.           my $valet = getserv($service, $proto);
  53.           unless ($valet) {
  54.               warn "$0: No service: $service/$proto\n"
  55.               next;
  56.           }
  57.           printf "service $service/$proto is port %d\n", $valet->port;
  58.           print "alias are @s_aliases\n" if @s_aliases;
  59.       }
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. NNNNeeeetttt::::::::sssseeeerrrrvvvveeeennnntttt((((3333))))                                                NNNNeeeetttt::::::::sssseeeerrrrvvvveeeennnntttt((((3333))))
  71.  
  72.  
  73.  
  74. NNNNOOOOTTTTEEEE
  75.      While this class is currently implemented using the Class::Struct module
  76.      to build a struct-like class, you shouldn't rely upon this.
  77.  
  78. AAAAUUUUTTTTHHHHOOOORRRR
  79.      Tom Christiansen
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.